package org.kymjs.emoji.control;

import java.util.ArrayList;
import java.util.List;

import org.kymjs.emoji.model.EmojiIcon;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * 表情适配器
 * 
 * @author kymjs
 * 
 */
public class EmojiGridAdapter extends BaseAdapter {

    private ImageView holder;
    private List<EmojiIcon> datas;
    private final Context cxt;

    public EmojiGridAdapter(Context cxt, List<EmojiIcon> datas) {
        this.cxt = cxt;
        if (datas == null) {
            datas = new ArrayList<EmojiIcon>(0);
        }
        this.datas = datas;
    }

    public void refresh(List<EmojiIcon> datas) {
        if (datas == null) {
            datas = new ArrayList<EmojiIcon>(0);
        }
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new ImageView(cxt);
        }
        holder.setImageResource(datas.get(position).getResId());
        return holder;
    }
}
